<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :dictMap="dictMapAsync"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      :defaultEventKey="defaultEventKey"
      :labelWidth="80"
    ></Ht-search-form>

    <!--    <div class="page-label-block">-->
    <!--      <span class="color-block">|</span>w-->
    <!--      <span class="page-label-name">-->
    <!--      租户管理-->
    <!--      </span>-->
    <!--    </div>-->

    <ht-table
      ref="dataTable"
      :multi-select="false"
      :showSerialNumber="false"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :reqConfig="regConfig"
      :defaultEventKey="defaultEventKey"
      :randomRowKey="true"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="50" fixed="right">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog :title="title" center :visible.sync="open" width="1024px" append-to-body :close-on-click-modal="false">
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="120px">
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>实时客户支付协议管理明细信息</span>
          </div>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="交易流水号" prop="id">
                <el-input v-model="detailForm.id" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="报文标识号" prop="pkgId">
                <el-input v-model="detailForm.pkgId" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="工作日期" prop="workdate">
                <el-date-picker
                  v-model="detailForm.workdate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="扣款管理类型" prop="dbtMngType">
                <el-select
                  style="width: 100%"
                  v-model="detailForm.dbtMngType"
                  placeholder="扣款管理类型"
                  :disabled="true"
                >
                  <el-option
                    v-for="dict in dictMap.DebitManagementTypeCode"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="扣款通知编号" prop="dbtNo">
                <el-input v-model="detailForm.dbtNo" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="地域标识" prop="regionId">
                <el-select style="width: 100%" v-model="detailForm.regionId" placeholder="地域标识" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.RegionId"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="统一社会信用代码" prop="uniformScCode">
                <el-input v-model="detailForm.uniformScCode" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="付款人数目" prop="payerNum">
                <el-input v-model="detailForm.payerNum" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
          <div class="discountReceipt-pick-operate-box">
            <div class="operate-box-bottom">
              <div class="bottom-content">
                <ht-table
                  ref="dataTable371"
                  :multi-select="false"
                  :showSerialNumber="false"
                  :dictMap="dictMap"
                  :queryParams="queryParams371"
                  :tableBindColumns="tableBindColumns371"
                  :reqConfig="regConfig371"
                  :showRightToolbar="false"
                  :randomRowKey="true"
                />
              </div>
            </div>
          </div>
        </el-card>

        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>客户账户扣款管理应答明细信息</span>
          </div>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="工作日期" prop="workdate372">
                <el-date-picker
                  v-model="detailForm.workdate372"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="业务状态" prop="bizStatus">
                <el-select style="width: 100%" v-model="detailForm.bizStatus" placeholder="业务状态" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.PROCESSSTATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="业务拒绝处理码" prop="bizRejectCode">
                <el-select
                  style="width: 100%"
                  v-model="detailForm.bizRejectCode"
                  placeholder="业务拒绝处理码"
                  :disabled="true"
                >
                  <el-option
                    v-for="dict in dictMap.CIS_CODE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="业务拒绝信息" prop="bizRejectInfo">
                <el-input type="textarea" v-model="detailForm.bizRejectInfo" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="业务处理参与机构" prop="bizProOrg">
                <el-input v-model="detailForm.bizProOrg" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="原扣款通知编号" prop="orgDbtNo">
                <el-input v-model="detailForm.orgDbtNo" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款人数目" prop="payerNum372">
                <el-input v-model="detailForm.payerNum372" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="录入操作员" prop="mdTlrno">
                <el-input v-model="detailForm.mdTlrno" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="录入时间" prop="mdTime">
                <el-date-picker
                  style="width: 100%"
                  v-model="detailForm.mdTime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="审核附言" prop="audRemarks">
                <el-input type="textarea" v-model="detailForm.audRemarks" />
              </el-form-item>
            </el-col>
          </el-row>

          <div class="discountReceipt-pick-operate-box">
            <div class="operate-box-bottom">
              <div class="bottom-content">
                <ht-table
                  ref="dataTable372"
                  :multi-select="false"
                  :showSerialNumber="false"
                  :dictMap="dictMap"
                  :queryParams="queryParams372"
                  :tableBindColumns="tableBindColumns372"
                  :reqConfig="regConfig372"
                  :showRightToolbar="false"
                  :randomRowKey="true"
                />
              </div>
            </div>
          </div>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="approve" v-loading="loading">审 核</el-button>
        <el-button type="danger" @click="reject" v-loading="loading">拒 绝</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPageMixin } from "@/libs/listPageMixin";
import {
  apiUrlConfigApprove,
  apiUrlConfigApprove371Qry,
  apiUrlConfigApprove372Qry,
  custAccDeductionAnswerApproveApprove,
  custAccDeductionAnswerApproveDetail,
  custAccDeductionAnswerApproveReject,
} from "@/api/cnaps/beps/372";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";

export default {
  name: "CustAccDeductionAnswerApprove",
  mixins: [listPageMixin],
  components: {},
  data() {
    return {
      // 查询参数
      queryParams: {
        id: undefined,
        workdate: undefined,
        workdate2: undefined,
      },
      queryParams371: {
        id: undefined,
      },
      queryParams372: {
        id: undefined,
      },
      loading: false,
      // 搜索
      defaultEventKey: "defaultEventKey",
      formOptions: [],
      //
      searchFormDictList: ["DebitManagementTypeCode", "RegionId", "PROCESSSTATUS", "CHECK_PROC_STATUS", "CIS_CODE"],
      // 列信息
      regConfig: apiUrlConfigApprove,

      regConfig371: apiUrlConfigApprove371Qry,

      regConfig372: apiUrlConfigApprove372Qry,

      tableBindColumns: [
        { prop: "id", label: "交易流水号", width: 180 },
        { prop: "workdate", label: "工作日期", type: "date", width: 120 },
        { prop: "pkgId", label: "报文标识号", width: 180 },
        { prop: "dbtMngType", label: "扣款管理类型", dictCode: "DebitManagementTypeCode", width: 120 },
        { prop: "dbtNo", label: "扣款通知编号", width: 120 },
        { prop: "regionId", label: "地域标识", dictCode: "RegionId", width: 120 },
        { prop: "uniformScCode", label: "统一社会信用代码", width: 180 },
        { prop: "payerNum", label: "付款人数目" },
      ],

      tableBindColumns371: [
        { prop: "dbtDtlId", label: "扣款明细标识号", width: 180 },
        { prop: "payerName", label: "付款人名称", width: 120 },
        { prop: "payerAddr", label: "付款人地址", width: 120 },
        { prop: "payerActno", label: "付款人账号", width: 120 },
        { prop: "payerAccBrno", label: "付款人开户行行号", width: 180 },
        { prop: "payerBrno", label: "付款行行号", width: 120 },
        { prop: "curcd", label: "币种", width: 120 },
        { prop: "amount", label: "金额", type: "price"},
      ],
      tableBindColumns372: [
        { prop: "dbtDtlId", label: "扣款结果明细标识号" },
        { prop: "dbtStatus", label: "扣款结果业务状态", dictCode: "CHECK_PROC_STATUS" },
      ],

      opButtonList: () => {
        return [
          {
            label: `${this.lang("common.add")}`,
            type: "primary",
            icon: "el-icon-plus",
            clickFun: () => {
              this.add();
            },
          },
        ];
      },

      dictMapAsync: {},
      // 弹出层标题
      title: "",
      titleDtb: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      detailForm: {},
      userInfo: {},
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,

      rules: {},
    };
  },
  mounted() {
    const formOptions = [
      // 普通搜索

      {
        type: "input",
        prop: "id",
        defaultAttr: {
          size: "small",
          label: "交易流水号",
          placeholder: "请输入交易流水号",
        },
      },
      {
        type: "dates",
        nameObj: {
          startTimeName: "workdate",
          endTimeName: "workdate2",
        },
        defaultAttr: {
          size: "small",
          label: "查询日期",
          placeholder: ["请输入工作开始日期", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "客户账户扣款管理应答审核明细";
      custAccDeductionAnswerApproveDetail(row).then((response) => {
        this.detailForm = response.result;
        this.queryParams371.id = this.detailForm.id;
        this.queryParams372.id = this.detailForm.id2;
        this.open = true;
        this.$nextTick(() => {
          this.$refs.dataTable371.doQuery();
          this.$refs.dataTable372.doQuery();
        });
      });
    },

    //点击审核按钮
    approve: function () {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          custAccDeductionAnswerApproveApprove(this.detailForm)
            .then((response) => {
              this.loading = true;
              this.msgSuccess("审核成功");
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },

    //点击拒绝按钮
    reject() {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          this.loading = true;
          custAccDeductionAnswerApproveReject(this.detailForm)
            .then((response) => {
              this.msgSuccess("拒绝成功");
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
